package com.test.socket;

import java.io.*;
import java.net.Socket;

/**
 * Created by jl on 2016/8/26.
 */
public class ClientSocket {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8084);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(socket.getOutputStream());
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String readLine;
        readLine = bufferedReader.readLine();
        while (!"bye bye".equals(readLine)) {
            writer.println(readLine);
            writer.flush();
            System.out.println("to server:" + readLine);
            System.out.println("from server:" + reader.readLine());
            //继续获取键盘输入
            readLine = bufferedReader.readLine();
        }
        reader.close();
        writer.close();
        socket.close();
    }
}
